//
//  HotTableViewCell.m
//  Mtime
//
//  Created by Mac on 15/7/31.
//  Copyright (c) 2015年 wxk. All rights reserved.
//

#import "HotTableViewCell.h"

@implementation HotTableViewCell

- (void)awakeFromNib {
    
}

- (void)setModel:(HotMovieModel *)model {

    _model = model;
    
    [_image setImageWithURL:[NSURL URLWithString:model.img]];
    
    _title.text = model.t;

    /*
     *label显示不同的字体。。。。。
     */
//    _rating.text = [NSString stringWithFormat:@"%.1f",[model.r floatValue]];
    [self loadRating];
    
    _count.text = [NSString stringWithFormat:@"今日%@家影院 %@场",model.NearestCinemaCount,model.NearestShowtimeCount];
    
    if ([model.commonSpecial isEqualToString:@""]) {
        
        /*
         *label显示不同的颜色。。。。。
         */
//        _comment.text = [NSString stringWithFormat:@"%@人在期待上映",model.wantedCount];
        
        [self loadWantedCount];
        
    }else {
    
        _comment.text = model.commonSpecial;
    }
    
    /*
     *设置时间格式。。。。。
     */
//    _time.text = model.rd;
    [self loadTime];
    
    
    UIImage *image1 = [UIImage imageNamed:@"icon_hot_show_IMAX3D"];
    UIImage *image2 = [UIImage imageNamed:@"icon_hot_show_IMAX"];
    UIImage *image3 = [UIImage imageNamed:@"icon_hot_show_DMAX"];
    
    /*
     *使图片一直紧靠左侧控件显示
     */

    if ([model.isIMAX3D intValue] == 1) {
        
        _image1.image = image1;
    }else if ([model.isIMAX intValue] == 1) {
        
        _image1.image = image2;
        _image3.hidden = YES;
    }else if ([model.isDMAX intValue] == 1) {
    
        _image1.image = image3;
        _image2.hidden = YES;
        _image3.hidden = YES;
    }else {
    
        _image1.hidden = YES;
        _image2.hidden = YES;
        _image3.hidden = YES;
    }
    
    
    if ([model.isIMAX intValue] == 1 && [model.isIMAX3D intValue] == 1) {
       
        _image2.image = image2;
    }else if ([model.isDMAX intValue] == 1){
        
        _image2.image = image3;
        _image3.hidden = YES;
    }else {
    
        _image2.hidden = YES;
        _image3.hidden = YES;
    }

    
    if ([model.isDMAX intValue] == 1 && [model.is3D intValue] == 1 && [model.isIMAX intValue] == 1) {
        _image3.image = image3;
    }else {
        _image3.hidden = YES;
    }
    
    
    
}

- (void)loadTime {
 
    /*
     设置时间格式
     */
    //1.获得对应时间的字符串
    NSString*origins =  [NSString stringWithFormat:@"%@",_model.rd]; //20140903
    //创建时间戳
    NSDateFormatter *fomate = [[NSDateFormatter alloc] init];
    //设置时间戳格式
    [fomate setDateFormat:@"yyyyMMdd"];
    NSDate *date = [fomate dateFromString:origins];
    [fomate setDateFormat:@"MM月dd日"];
    NSString*news =  [fomate stringFromDate:date];
    _time.text = [NSString stringWithFormat:@"%@上映",news];
    
}

- (void)loadRating {

    NSString *str;
    if ([_model.r floatValue] <= 0) {
        
        str = @"0.0";
        
    }else {
    
        str = [NSString stringWithFormat:@"%.1f",[_model.r floatValue]];
        
    }
    
    /*
     *label显示不同的字体
     */
    //根据原有的字符串  初始化出富文本
    NSMutableAttributedString *mstr = [[NSMutableAttributedString alloc] initWithString:str];
    /*
     *6.9
     */
    
    //给富文本做出需要的设置
    /*
     [mstr addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],
     NSForegroundColorAttributeName:[UIColor redColor]} range:NSMakeRange(1, 2)];
     */
    
    [mstr addAttribute:NSFontAttributeName
                 value:[UIFont systemFontOfSize:12]
                 range:NSMakeRange(1, 2)];
    
    //给label的富文本参数赋值
    _rating.attributedText = mstr;

}

- (void)loadWantedCount {

    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@人在期待上映",_model.wantedCount]];
    
    /*
     *获得改变字体的字符范围
     *根据wantedCount属性名所占的字符长度来截取
     */
    [attString addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, [NSString stringWithFormat:@"%@",_model.wantedCount].length)];
    
    _comment.attributedText = attString;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
